package com.jiyun.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jiyun.common.result.Result;
import com.jiyun.entity.pojo.Particulars;
import com.jiyun.entity.vo.OrdersVO;
import com.jiyun.entity.vo.ParticularsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.jiyun.service.ParticularsService;

import java.util.List;


/**
 * (Particulars)表控制层
 *
 * @author LYT
 * @since 2025-01-16 18:36:14
 */
@RestController
@RequestMapping("particulars")
@Api(tags = "操作接口")
public class ParticularsController {
    @Autowired
    private ParticularsService particularsService;

    @PostMapping("update/{orderId}")
    @ApiOperation("修改")
    public Result updateById(@PathVariable  Integer orderId) {
        LambdaQueryWrapper<Particulars> eq = new LambdaQueryWrapper<Particulars>().eq(Particulars::getOrderid, orderId);
        Particulars particulars = particularsService.getOne(eq);
       particulars.setStatus("已完成");
        particularsService.updateById(particulars);
        return Result.ok();
    }
    @PostMapping("qx/{orderId}")
    @ApiOperation("取消订单")
    public Result qx(@PathVariable  Integer orderId) {
        LambdaQueryWrapper<Particulars> eq = new LambdaQueryWrapper<Particulars>().eq(Particulars::getOrderid, orderId);
        Particulars particulars = particularsService.getOne(eq);
        particulars.setStatus("已取消");
        particularsService.updateById(particulars);
        return Result.ok();
    }


    @GetMapping("findById/{orderId}")
    @ApiOperation("根据id查询单个")
    public List<ParticularsVO> getByOrderId(@PathVariable Integer orderId) {
        return particularsService.getByOrderId(orderId);
    }

    @PostMapping("findAll")
    @ApiOperation("查询所有")
    public List<ParticularsVO> findAll(@RequestBody ParticularsVO particularsVO) {
        return particularsService.findAll(particularsVO);
    }

    @PostMapping("/AddOrders")
    public Integer AddOrders(@RequestBody OrdersVO ordersVO) {
        ordersVO.setStatus("待支付，剩余时间");
        return particularsService.AddOrders(ordersVO);
    }


    @PostMapping("/findList")
    public List<Particulars> findList() {
        return particularsService.list();
    }







}

